package com.fyzk.activity.lottery.jc.football;

import com.fyzk.activity.lottery.basketball.JCLQFragmentActivityI;
import com.fyzk.activity.lottery.jc.football.guoguan.JC_GuoGuanInfor;
import com.fyzk.model.JCLQMatchData;
import com.fyzk.utils.LotteryIDUtils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * <p>
 *
 * @author Administrator
 * @mood
 * @description
 * @date 2018/6/4 17:24
 * </p>
 */
public class JZBetContentUtil {

    /**
     * 获取投注内容
     * 混合过关
     * @param infos
     */
    public static String getContentHG(List<JCInfo> infos, boolean isdanguan, String result) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isdanguan);
        String content = "";
        for (int i = 0; i < chuans.size(); i++) {
            String n = "";
            String danCodes = "";
            for (int j = 0; j < infos.size(); j++) {
                JCInfo info = infos.get(j);
                String danChang = "";
                if (info.getOnclikNum() > 0) {
                    danChang += JC_GuoGuanInfor.getHunHes(info);
                }

                if (!danChang.equals("")) {
                    if (info.isDan()) {
                        danCodes += danChang + "|";
                    } else {
                        n += danChang + "|";
                    }
                }
            }

            if (!danCodes.equals("")) {
                danCodes = danCodes.substring(0, danCodes.length() - 1);
                danCodes += "#";
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }
            content += danCodes + n + "!";
        }
        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }
        return content;
    }

    /**
     * 获取投注内容
     * 胜平负
     * @param infos
     */
    public static String getContentSPF(List<JCInfo> infos, boolean isDanguan, String result) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isDanguan);
        String content = "";
        for (int i = 0; i < chuans.size(); i++) {
            boolean hasSPF = false;
            boolean hasRSPF = false;
            for (JCInfo info : infos) {
                String[] keys = {info.VS_3, info.VS_1, info.VS_0};
                for (int j = 0; j < keys.length; j++) {
                    if (info.btnHGPojo.get(keys[j]).isSel) {
                        hasSPF = true;
                    }
                }
                String[] keys_r = {info.LETVS_0, info.LETVS_1, info.LETVS_3};
                for (int j = 0; j < keys_r.length; j++) {
                    if (info.btnHGPojo.get(keys_r[j]).isSel) {
                        hasRSPF = true;
                    }
                }
            }
            int lotteryId_real = LotteryIDUtils.JZSPF_LOTTERY_ID_INT;
            if (hasSPF && hasRSPF) {
                lotteryId_real = LotteryIDUtils.JZHH_LOTTERY_ID_INT;
            } else if (hasSPF) {
                lotteryId_real = LotteryIDUtils.JZSPF_LOTTERY_ID_INT;
            } else if (hasRSPF) {
                lotteryId_real = LotteryIDUtils.JZRFSPF_LOTTERY_ID_INT;
            }

            String n = "";
            String danCodes = "";
            for (int j = 0; j < infos.size(); j++) {
                JCInfo info = infos.get(j);
                String danChang = "";
                if (info.getOnclikNum() != 0) {
                    if (lotteryId_real == LotteryIDUtils.JZHH_LOTTERY_ID_INT) {
                        String spf = "";
                        String rspf = "";
                        if (info.btnHGPojo.get(info.VS_0).isSel) {
                            spf += "0,";
                        }
                        if (info.btnHGPojo.get(info.VS_1).isSel) {
                            spf += "1,";
                        }
                        if (info.btnHGPojo.get(info.VS_3).isSel) {
                            spf += "3,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_0).isSel) {
                            rspf += "0,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_1).isSel) {
                            rspf += "1,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_3).isSel) {
                            rspf += "3,";
                        }
                        if (!spf.equals("")) {
                            spf = spf.substring(0, spf.length() - 1);
                            spf = info.getMatchNum() + "*" + LotteryIDUtils.JZSPF_LOTTERY_ID_INT + "(" + spf + ")|";
                        }
                        if (!rspf.equals("")) {
                            rspf = rspf.substring(0, rspf.length() - 1);
                            rspf = info.getMatchNum() + "*" + LotteryIDUtils.JZRFSPF_LOTTERY_ID_INT + "(" + rspf
                                    + ")|";
                        }
                        result = spf + rspf;
                        if (!result.equals("")) {
                            result = result.substring(0, result.length() - 1);
                        }
                        danChang += result;
                    } else {
                        danChang = info.getMatchNum() + "(";
                        if (info.btnHGPojo.get(info.VS_0).isSel) {
                            danChang += "0,";
                        }
                        if (info.btnHGPojo.get(info.VS_1).isSel) {
                            danChang += "1,";
                        }
                        if (info.btnHGPojo.get(info.VS_3).isSel) {
                            danChang += "3,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_0).isSel) {
                            danChang += "0,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_1).isSel) {
                            danChang += "1,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_3).isSel) {
                            danChang += "3,";
                        }
                        danChang = danChang.substring(0, danChang.length() - 1);
                        danChang += ")";
                    }
                }
                if (!danChang.equals("")) {
                    if (info.isDan()) {
                        danCodes += danChang + "|";
                    } else {
                        n += danChang + "|";
                    }
                }
            }
            if (!danCodes.equals("")) {
                danCodes = danCodes.substring(0, danCodes.length() - 1);
                danCodes += "#";
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }
            content += danCodes + n + "!";
        }
        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }

        return content;
    }

    /**
     * 获取投注内容   301012001-20140304002(10)|20140304003(13)^
     * 半全场
     * @param infos
     */
    public static String getContentBQC(List<JCInfo> infos, boolean isdanguan, String result) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isdanguan);
        String content = "";

        for (int i = 0; i < chuans.size(); i++) {
            String n = "";
            String danCodes = "";
            for (int j = 0; j < infos.size(); j++) {
                JCInfo info = infos.get(j);
                StringBuffer danChang = new StringBuffer();
                if (info.getOnclikNum() > 0) {
                    danChang.append(info.getMatchNum());
                    danChang.append("(");
                    Set<String> keys = info.btnHGPojo.keySet();
                    Iterator<String> keyIterator = keys.iterator();
                    while (keyIterator.hasNext()) {
                        String key = keyIterator.next();
                        JCInfo.SPInfo spInfo = info.btnHGPojo.get(key);
                        if (spInfo.isSel) {
                            danChang.append(spInfo.codeValue);
                            danChang.append(",");
                        }
                    }

                    danChang.deleteCharAt(danChang.length() - 1);
                    danChang.append(")");
                    if (!danChang.equals("")) {
                        if (info.isDan()) {
                            danCodes += danChang + "|";
                        } else {
                            n += danChang + "|";
                        }
                    }
                }

            }
            if (!danCodes.equals("")) {
                danCodes = danCodes.substring(0, danCodes.length() - 1);
                danCodes += "#";
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }

            content += danCodes + n + "!";
        }

        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }

        return content;
    }

    /**
     * 获取投注内容	301012001-20140304002(13)|20140304007(32,11)^
     * 比分
     * @param infos
     */
    public static String getContentBF(List<JCInfo> infos, boolean isdanguan, String result) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isdanguan);
        String content = "";
        for (int i = 0; i < chuans.size(); i++) {
            String n = "";
            String danCodes = "";
            for (int j = 0; j < infos.size(); j++) {
                JCInfo info = infos.get(j);
                String danChang = "";


                if (!"".equals(info.getResult())) {
                    danChang = info.getMatchNum() + "(";

                    List<String> results = JC_GuoGuanInfor.getBiFenIds(info.getResult());
                    for (String string : results) {
                        danChang += string.trim() + ",";
                    }

                    danChang = danChang.substring(0, danChang.length() - 1);
                    danChang += ")";
                }

                if (!danChang.equals("")) {
                    if (info.isDan()) {
                        danCodes += danChang + "|";
                    } else {
                        n += danChang + "|";
                    }
                }
            }
            if (!danCodes.equals("")) {
                danCodes = danCodes.substring(0, danCodes.length() - 1);
                danCodes += "#";
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }

            content += danCodes + n + "!";
        }

        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }
        return content;
    }

    /**
     * 获取投注内容   301012001-20140311002(3,4)|20140311004(2,3)^
     * 总进球
     * @param infos
     */
    public static String getContentZJQ(List<JCInfo> infos, boolean isdanguan, String result) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isdanguan);
        StringBuffer content = new StringBuffer();
        for (int i = 0; i < chuans.size(); i++) {
            List<String> singleTeamCodes = new ArrayList<>();
            List<String> singleTeamCodes_d = new ArrayList<>();
            for (int j = 0; j < infos.size(); j++) {
                JCInfo info = infos.get(j);
                StringBuffer danChang = new StringBuffer();
                if (info.getOnclikNum() > 0) {
                    danChang.append(info.getMatchNum());
                    danChang.append("(");
                    Set<String> keys = info.btnHGPojo.keySet();
                    Iterator<String> keyIterator = keys.iterator();
                    while (keyIterator.hasNext()) {
                        String key = keyIterator.next();
                        if (info.btnHGPojo.get(key).isSel) {
                            if (key.equals(info.SCORE_0)) {
                                danChang.append("0,");
                            } else if (key.equals(info.SCORE_1)) {
                                danChang.append("1,");
                            } else if (key.equals(info.SCORE_2)) {
                                danChang.append("2,");
                            } else if (key.equals(info.SCORE_3)) {
                                danChang.append("3,");
                            } else if (key.equals(info.SCORE_4)) {
                                danChang.append("4,");
                            } else if (key.equals(info.SCORE_5)) {
                                danChang.append("5,");
                            } else if (key.equals(info.SCORE_6)) {
                                danChang.append("6,");
                            } else if (key.equals(info.SCORE_7)) {
                                danChang.append("7,");
                            }
                        }
                    }
                    danChang.deleteCharAt(danChang.length() - 1);
                    danChang.append(")");
                    if (info.isDan()) {
                        singleTeamCodes_d.add(danChang.toString());
                    } else {
                        singleTeamCodes.add(danChang.toString());
                    }
                }
            }

            if (singleTeamCodes_d.size() > 0) {
                for (String team : singleTeamCodes_d) {
                    content.append(team);
                    content.append("|");
                }
                content = content.deleteCharAt(content.length()-1);
                content.append("#");
                for (String team : singleTeamCodes) {
                    content.append(team);
                    content.append("|");
                }
                content = content.deleteCharAt(content.length()-1);
                content.append("^!");
            } else {
                for (String team : singleTeamCodes) {
                    content.append(team);
                    content.append("|");
                }
                content = content.deleteCharAt(content.length() - 1);
                content.append("^!");
            }
        }
        return content.deleteCharAt(content.length() - 1).toString();
    }

    ///////////////////////////////////////////以下为篮球///////////////////////////////////////////

    /**
     * 获取投注内容
     * 篮球混合过关
     * @param isdanguan
     * @param result
     * @return
     */
    public static String getContentLQHG(boolean isdanguan, String result) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isdanguan);
        String content = "";
        for (int i = 0; i < chuans.size(); i++) {
            String n = "";
            for (int j = 0; j < JCLQFragmentActivityI.matchs.size(); j++) {
                JCLQMatchData info = JCLQFragmentActivityI.matchs.get(j);
                // * 竞彩混合注码格式
                // 300512001-20140330302*3004(2)|20140330302*3001(1,3)|20140330307
                // * *3001(0)^ 与非混合的区别是，赛事编号后面多了一个玩法字段。
                StringBuffer danChang = new StringBuffer();
                if (info.clickNum != 0) {
                    danChang.append(info.getMatchNum());
                    danChang.append("*");
                    StringBuffer sb_sf = new StringBuffer();
                    {
                        JCLQMatchData.SPInfo sf_s = info.plInfos.get(0);
                        JCLQMatchData.SPInfo sf_f = info.plInfos.get(1);

                        if (sf_s.isSel) {
                            sb_sf.append(sf_s.codeValue);
                            sb_sf.append(",");
                        }
                        if (sf_f.isSel) {
                            sb_sf.append(sf_f.codeValue);
                            sb_sf.append(",");
                        }
                    }
                    if (sb_sf.length() > 0) {
                        danChang.append(LotteryIDUtils.JLSF_LOTTERY_ID_INT);
                        danChang.append("(");
                        danChang.append(sb_sf.substring(0, sb_sf.length() - 1));
                        danChang.append(")");
                        danChang.append("|");
                        danChang.append(info.getMatchNum());
                        danChang.append("*");
                    }

                    StringBuffer sb_rsf = new StringBuffer();
                    {
                        JCLQMatchData.SPInfo rsf_s = info.plInfos.get(2);
                        JCLQMatchData.SPInfo rsf_f = info.plInfos.get(3);
                        if (rsf_s.isSel) {
                            sb_rsf.append(rsf_s.codeValue);
                            sb_rsf.append(",");
                        }
                        if (rsf_f.isSel) {
                            sb_rsf.append(rsf_f.codeValue);
                            sb_rsf.append(",");
                        }
                    }
                    if (sb_rsf.length() > 0) {
                        danChang.append(LotteryIDUtils.JLRSF_LOTTERY_ID_INT);
                        danChang.append("(");
                        danChang.append(sb_rsf.substring(0, sb_rsf.length() - 1));
                        danChang.append(")");
                        danChang.append("|");
                        danChang.append(info.getMatchNum());
                        danChang.append("*");
                    }
                    StringBuffer sb_dxf = new StringBuffer();
                    {
                        JCLQMatchData.SPInfo dxf_d = info.plInfos.get(4);
                        JCLQMatchData.SPInfo dxf_x = info.plInfos.get(5);
                        if (dxf_d.isSel) {
                            sb_dxf.append(dxf_d.codeValue);
                            sb_dxf.append(",");
                        }
                        if (dxf_x.isSel) {
                            sb_dxf.append(dxf_x.codeValue);
                            sb_dxf.append(",");
                        }
                    }
                    if (sb_dxf.length() > 0) {
                        danChang.append(LotteryIDUtils.JLDXF_LOTTERY_ID_INT);
                        danChang.append("(");
                        danChang.append(sb_dxf.substring(0, sb_dxf.length() - 1));
                        danChang.append(")");
                        danChang.append("|");
                        danChang.append(info.getMatchNum());
                        danChang.append("*");
                    }
                    StringBuffer sb_sfc = new StringBuffer();
                    {
                        for (int x = 6; x < (info.plInfos.size()); x++) {
                            JCLQMatchData.SPInfo sp = info.plInfos.get(x);
                            if (sp.isSel) {
                                sb_sfc.append(sp.codeValue);
                                sb_sfc.append(",");
                            }
                        }
                    }
                    if (sb_sfc.length() > 0) {
                        danChang.append(LotteryIDUtils.JLSFC_LOTTERY_ID_INT);
                        danChang.append("(");
                        danChang.append(sb_sfc.substring(0, sb_sfc.length() - 1));
                        danChang.append(")");
                        danChang.append("|");
                        danChang.append(info.getMatchNum());
                        danChang.append("*");
                    }
                }
                if (danChang.length() > 0) {
                    n += danChang.substring(0,
                            danChang.length() - (info.getMatchNum().length() + 2))
                            + "|";
                }
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }
            content += n + "!";
        }
        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }
        return content;
    }

    /**
     * 获取投注内容
     * 篮球大小分
     * @param isdanguan
     * @param result
     * @return
     */
    public static String getContentLQDXF(boolean isdanguan, String result) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isdanguan);
        String content = "";
        for (int i = 0; i < chuans.size(); i++) {
            String n = "";
            for (int j = 0; j < JCLQFragmentActivityI.matchs.size(); j++) {
                JCLQMatchData info = JCLQFragmentActivityI.matchs.get(j);
                StringBuffer danChang = new StringBuffer();
                JCLQMatchData.SPInfo sp_d = info.splInfos.get(info.DXF_1);
                JCLQMatchData.SPInfo sp_x = info.splInfos.get(info.DXF_2);

                if (info.clickNum>0) {
                    danChang.append(info.getMatchNum());
                    danChang.append("(");
                    if (sp_d.isSel) {
                        danChang.append("1,");
                    }
                    if (sp_x.isSel) {
                        danChang.append("2,");
                    }
                    danChang.deleteCharAt(danChang.length()-1);
                    danChang .append(")");
                }

                if (!danChang.toString().equals("")) {
                    n += danChang + "|";
                }
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }

            content += n + "!";
        }

        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }

        return content;
    }

    /**
     * 获取投注内容
     * 篮球胜分差
     * @param isdanguan
     * @param result
     * @return
     */
    public static String getContentLQSFC(boolean isdanguan, String result) {
        /**
         * 竞彩注码基本格式
         * 300612001-20140101001(0,1,3)|20140101002(0,1,3)|20140101003(0,1,3)^
         * 3006：彩种编号 1：单复式 2001:2串1 20140101001:场次编号 (0,1,3)：投注内容
         *
         * 竞彩混合注码格式
         * 300512001-20140330302*3004(2)|20140330302*3001(1,3)|20140330307
         * *3001(0)^ 与非混合的区别是，赛事编号后面多了一个玩法字段。
         *
         * 胆拖
         * 300622001-20140101001(0,1,3)$20140101002(0,1,3)|20140101003(0,1,3)^
         * $前面为胆码 $后面为托码
         **/
        String[] zhumas = {"01", "02", "03", "04", "05", "06", "11", "12", "13", "14", "15", "16" };
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isdanguan);
        String content = "";
        for (int i = 0; i < chuans.size(); i++) {
            String n = "";
            for (int j = 0; j < JCLQFragmentActivityI.matchs.size(); j++) {
                JCLQMatchData info = JCLQFragmentActivityI.matchs.get(j);
                StringBuffer danChang = new StringBuffer();
                if (info.clickNum>0) {
                    danChang.append(info.getMatchNum());
                    danChang.append("(");
                    List<JCLQMatchData.SPInfo> infos = info.plInfos;
                    for (JCLQMatchData.SPInfo info1 : infos) {
                        int index = infos.indexOf(info1);
                        if (info1.isSel) {
                            danChang.append(zhumas[index]);
                            danChang.append(",");
                        }
                    }
                    danChang.deleteCharAt(danChang.length() - 1);
                    danChang.append(")");
                    if (!danChang.equals("")) {
                        n += danChang + "|";
                    }
                }
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }
            content += n + "!";
        }
        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }
        return content;
    }

    /**
     * 获取投注内容
     * 篮球胜负
     * @param
     * @param result
     * @return
     */
    public static String getContentLQSF(boolean isDanguan, String result, int lotteryId) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isDanguan);
        String content = "";
        for (int i = 0; i < chuans.size(); i++) {
            String n = "";
            for (int j = 0; j < JCLQFragmentActivityI.matchs.size(); j++) {
                JCLQMatchData info = JCLQFragmentActivityI.matchs.get(j);
                StringBuffer danChang = new StringBuffer();
                if (info.clickNum != 0) {
                    danChang.append(info.getMatchNum());
                    danChang.append("(");

                    switch (lotteryId) {
                        case LotteryIDUtils.JLRSF_LOTTERY_ID_INT:
                            if (info.splInfos.get(info.LETVS_0).isSel) {
                                danChang.append("0,");
                            }
                            if (info.splInfos.get(info.LETVS_3).isSel) {
                                danChang.append("3,");
                            }
                            break;
                        case LotteryIDUtils.JLSF_LOTTERY_ID_INT:
                            if (info.splInfos.get(info.VS_0).isSel) {
                                danChang.append("0,");
                            }
                            if (info.splInfos.get(info.VS_3).isSel) {
                                danChang.append("3,");
                            }
                            break;
                    }

                    danChang = danChang.deleteCharAt(danChang.length() - 1);
                    danChang.append(")");
                }

                if (!danChang.toString().equals("")) {
                    n += danChang + "|";
                }
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }
            content += n + "!";
        }
        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }
        return content;
    }

}
